package com.ruoyi.luban.service.impl;

import java.text.SimpleDateFormat;
import java.util.*;
import java.util.concurrent.ExecutorService;
import java.util.concurrent.Executors;
import java.util.regex.Matcher;
import java.util.regex.Pattern;

import cn.binarywang.wx.miniapp.api.WxMaService;
import cn.binarywang.wx.miniapp.bean.WxMaSubscribeMessage;
import com.ruoyi.common.core.utils.DateUtils;
import com.ruoyi.common.core.utils.StringUtils;
import com.ruoyi.common.core.web.domain.AjaxResult;
import com.ruoyi.luban.config.WxMessageProperties;
import com.ruoyi.luban.domain.*;
import com.ruoyi.luban.domain.dto.CreateOrderDto;
import com.ruoyi.luban.domain.dto.FindOrderDto;
import com.ruoyi.luban.domain.dto.UpdateOrderDto;
import com.ruoyi.luban.domain.vo.DealerOrderVo;
import com.ruoyi.luban.domain.vo.LoginUserAndTokenVo;
import com.ruoyi.luban.domain.vo.OrderVo;
import com.ruoyi.luban.mapper.*;
import me.chanjar.weixin.common.error.WxErrorException;
import org.apache.commons.lang3.RandomStringUtils;
import org.apache.commons.math3.util.MathUtils;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.BeanUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.data.redis.core.RedisTemplate;
import org.springframework.stereotype.Service;
import com.ruoyi.luban.service.IPOrderService;
import org.springframework.transaction.annotation.Transactional;

/**
 * 订单Service业务层处理
 * 
 * @author ruoyi
 * @date 2024-01-28
 */
@Service
public class POrderServiceImpl implements IPOrderService 
{
    private static Logger logger = LoggerFactory.getLogger(POrderServiceImpl.class);
    @Autowired
    private POrderMapper pOrderMapper;
    @Autowired
    private PUserAddressMapper userAddressMapper;
    @Autowired
    private PSchoolMapper pSchoolMapper;
    @Autowired
    private PDealerSchoolMapper dealerSchoolMapper;
    @Autowired
    private PDealerMapper dealerMapper;
    @Autowired
    private PWxLoginUserMapper pWxLoginUserMapper;
    @Autowired
    private PFileInfoMapper fileInfoMapper;
    @Autowired
    private WxMessageProperties wxMessageProperties;
    @Autowired
    private WxMaService wxMaService;
    @Autowired
    private PWxUserMapper pWxUserMapper;
    /**
     * 查询订单
     * 
     * @param id 订单主键
     * @return 订单
     */
    @Override
    public POrder selectPOrderById(Long id)
    {
        return pOrderMapper.selectPOrderById(id);
    }

    /**
     * 查询订单列表
     * 
     * @param pOrder 订单
     * @return 订单
     */
    @Override
    public List<POrder> selectPOrderList(POrder pOrder)
    {
        return pOrderMapper.selectPOrderList(pOrder);
    }

    /**
     * 新增订单
     * 
     * @param pOrder 订单
     * @return 结果
     */
    @Override
    public int insertPOrder(POrder pOrder)
    {
        //订单编号 随机五位+当前时间
        String orderNo = RandomStringUtils.randomAlphabetic(5) + new SimpleDateFormat("yyyyMMddHHmmssSSSS").format(new Date());
        pOrder.setOrderNo(orderNo);
        pOrder.setCreateTime(DateUtils.getNowDate());
        return pOrderMapper.insertPOrder(pOrder);
    }

    /**
     * 修改订单
     * 
     * @param pOrder 订单
     * @return 结果
     */
    @Override
    public int updatePOrder(POrder pOrder)
    {
        pOrder.setUpdateTime(DateUtils.getNowDate());
        return pOrderMapper.updatePOrder(pOrder);
    }

    /**
     * 批量删除订单
     * 
     * @param ids 需要删除的订单主键
     * @return 结果
     */
    @Override
    public int deletePOrderByIds(Long[] ids)
    {
        return pOrderMapper.deletePOrderByIds(ids);
    }

    /**
     * 删除订单信息
     * 
     * @param id 订单主键
     * @return 结果
     */
    @Override
    public int deletePOrderById(Long id)
    {
        return pOrderMapper.deletePOrderById(id);
    }

    @Override
//    @Transactional
    public AjaxResult createOrder(LoginUserAndTokenVo info, CreateOrderDto pOrder) {
        //用户地址
        PUserAddress userAddress = userAddressMapper.selectPUserAddressById(pOrder.getAddressId());
        if(userAddress == null){
            return AjaxResult.error("请先重新添加地址信息");
//            return 0;
        }
        if(!"2".equals(info.getLoginType())){
            return AjaxResult.error("当前登录用户非学校，不予该操作");
        }
        //订单编号 随机五位+当前时间
        String orderNo =  new SimpleDateFormat("yyyyMMddHHmmssSSSS").format(new Date()) +RandomStringUtils.randomAlphabetic(5);
        pOrder.setOrderNo(orderNo);
        //获取登录用户id
        pOrder.setUserId(info.getLoginUser().getLoginUserId());
        pOrder.setPhone(userAddress.getPhone());
        if(info.getSchoolId() == null){
            return AjaxResult.error("请先重新添加地址信息");
//            PSchool pSchool = pSchoolMapper.selectPSchoolById(userAddress.getSchoolId());
//            userAddress.setSchoolId(pSchool.getId());
//            info.setSchoolId(pSchool.getId());
//            info.setSchoolName(pSchool.getSchoolName());
//            pOrder.setSchoolId(info.getSchoolId());
        }
        pOrder.setSchoolId(info.getSchoolId());
        String address = info.getSchoolName() + " " + userAddress.getDetailAddress();
        pOrder.setAddress(address);
        //获取该学校的签约经销商
        PDealerSchool pDealerSchool = new PDealerSchool();
        pDealerSchool.setSchoolId(info.getSchoolId());
        List<PDealerSchool> pDealerSchools = dealerSchoolMapper.selectPDealerSchoolList(pDealerSchool);
        if(pDealerSchools.isEmpty()){
            return AjaxResult.error("该学校未签约经销商，请与负责人联系");
        }
        pOrder.setDealerId(pDealerSchools.get(0).getDealerId());
        //状态（0 初始化 1 预约待报价状态 2 已接单 3 已报价待处理状态 4 已报价待结算状态 5 完成了结算，已完成状态 -1 已关闭状态（后台手工））
        pOrder.setStatus("1");
        pOrder.setCreateTime(DateUtils.getNowDate());
        pOrder.setUpdateTime(new Date());
        pOrder.setCreateBy(info.getLoginUser().getNickName());
        pOrder.setUpdateBy(info.getLoginUser().getNickName());
        int result = pOrderMapper.insertPOrder(pOrder);
        //订单图片
        List<Long> picIds = pOrder.getPicIds();
        if(picIds != null && !picIds.isEmpty()){
            for(Long pic : picIds){
                PFileInfo file = fileInfoMapper.selectPFileInfoById(pic);
                if(file != null){
                    file.setContactId(pOrder.getId());
                    file.setUpdateBy(info.getLoginUser().getNickName());
                    file.setUpdateTime(new Date());
                    fileInfoMapper.updatePFileInfo(file);
                }
            }
        }
        if (result > 0){
            PWxLoginUser pWxLoginUser = pWxLoginUserMapper.selectPWxLoginUserByContactId(pOrder.getDealerId());
            if(pWxLoginUser != null && !"0".equals(pWxLoginUser.getSubscribeStatus())) {
                OrderWXMessage orderWXMessage = new OrderWXMessage();
                orderWXMessage.setCharacterString1(pOrder.getOrderNo());
                orderWXMessage.setThing2(pOrder.getRepairedPrice());
                orderWXMessage.setPhrase3("预约待报价");
                orderWXMessage.setTime4(pOrder.getCreateTime());
                orderWXMessage.setThing5("您好，学校下单成功，请前往订单报价。");

                orderWXMessage.setToUser(pWxLoginUser.getOpenId());

                boolean seneStatue = this.sendMessage(wxMessageProperties.getPage(),orderWXMessage);
                if (seneStatue) {
                    pOrder.setStatus("2");
                    pOrder.setUpdateTime(new Date());
                    pOrder.setUpdateBy(info.getLoginUser().getNickName());
                    pOrderMapper.updatePOrder(pOrder);
                }
            }
        }
        return AjaxResult.success();
    }

//    @Transactional
    @Override
    public AjaxResult updatePrice(LoginUserAndTokenVo info, UpdateOrderDto pOrder) {
        //状态
        // （0 初始化 1 预约待报价状态 2 已接单,提醒到供销商 3 已报价待处理状态
        // 4 同意报价待处理状态 5 供销商处理完成，待学校验收
        // 6 学校验收通过 7后台完成了结算，已完成状态
        // -1 已关闭状态（后台手工））-2 不同意报价 -3 学校验收不通过
        // 判断是否是签约供销商TODO
        //判断状态
        POrder preOrder = pOrderMapper.selectPOrderById(pOrder.getId());
        if(!preOrder.getStatus().equals("1") && !preOrder.getStatus().equals("2")
                && !preOrder.getStatus().equals("-2")){
            return AjaxResult.error("订单未处于待报价状态，请等待");
        }
        if(!"1".equals(info.getLoginType())){
            return AjaxResult.error("当前登录用户非经销商，不予该操作");
        }
        String regex = "^\\d+(\\.\\d{1,2})?$"; // 定义金额格式的正则表达式

        Pattern pattern = Pattern.compile(regex);
        Matcher matcher = pattern.matcher(pOrder.getRepairedPrice());
        if(StringUtils.isEmpty(pOrder.getRepairedPrice())){
            return AjaxResult.error("请输入金额");
        }
        if (!matcher.matches()){
            return AjaxResult.error("金额输入不正确，请重新输入");
        }
        pOrder.setStatus("3");
        pOrder.setUpdateTime(new Date());
        pOrder.setUpdateBy(info.getLoginUser().getNickName());
        int result = pOrderMapper.updatePOrder(pOrder);
        if (result > 0){
            PWxLoginUser pWxLoginUser = pWxLoginUserMapper.selectPWxLoginUserById(preOrder.getUserId());
            if(pWxLoginUser != null && !"0".equals(pWxLoginUser.getSubscribeStatus())) {
                OrderWXMessage orderWXMessage = new OrderWXMessage();
                orderWXMessage.setCharacterString1(preOrder.getOrderNo());
                orderWXMessage.setThing2(pOrder.getRepairedPrice());
                orderWXMessage.setPhrase3("报价待处理");
                orderWXMessage.setTime4(pOrder.getUpdateTime());
                orderWXMessage.setThing5("您好，经销商已报价，请前往订单进行处理。");
                orderWXMessage.setToUser(pWxLoginUser.getOpenId());
                this.sendMessage(wxMessageProperties.getSchoolPage(),orderWXMessage);
            }
        }
        return AjaxResult.success("报价成功,已成功通知学校");
    }

//    @Transactional
    @Override
    public AjaxResult agreePrice(LoginUserAndTokenVo info, UpdateOrderDto pOrder) {
        POrder preOrder = pOrderMapper.selectPOrderById(pOrder.getId());
        if(!preOrder.getStatus().equals("3")){
            return AjaxResult.error("订单未处于待确认报价状态，请等待供销商提供报价");
        }
        if(!"2".equals(info.getLoginType())){
            return AjaxResult.error("当前登录用户非学校，不予该操作");
        }
        pOrder.setUpdateTime(new Date());
        pOrder.setUpdateBy(info.getLoginUser().getNickName());
        int result = pOrderMapper.updatePOrder(pOrder);
        if (result > 0){
            PWxLoginUser pWxLoginUser = pWxLoginUserMapper.selectPWxLoginUserByContactId(preOrder.getDealerId());
            if(pWxLoginUser != null && !"0".equals(pWxLoginUser.getSubscribeStatus())) {
                OrderWXMessage orderWXMessage = new OrderWXMessage();
                orderWXMessage.setCharacterString1(preOrder.getOrderNo());
                orderWXMessage.setThing2(preOrder.getRepairedPrice());
                orderWXMessage.setPhrase3("同意待处理");
                orderWXMessage.setTime4(pOrder.getUpdateTime());
                orderWXMessage.setThing5("您好，学校已同意报价，请前往订单进行处理。");

                orderWXMessage.setToUser(pWxLoginUser.getOpenId());
                this.sendMessage(wxMessageProperties.getPage(),orderWXMessage);
            }
        }
        return AjaxResult.success("订单创建成功，请等待经销商接单");
    }
//    @Transactional
    @Override
    public AjaxResult completeOrder(LoginUserAndTokenVo info, UpdateOrderDto pOrder) {
        //（0 初始化 1 预约待报价状态 2 已接单,提醒到供销商 3 已报价待处理状态 4 同意报价待处理状态 5 供销商处理完成，待学校验收 6 学校验收通过 7后台完成了结算，已完成状态  -1 已关闭状态（后台手工））-2 不同意报价 -3 学校验收不通过
        POrder preOrder = pOrderMapper.selectPOrderById(pOrder.getId());
        if(!preOrder.getStatus().equals("4")){
            return AjaxResult.error("订单未处于待完成状态，请等待学校同意报价");
        }
        if(!"1".equals(info.getLoginType())){
            return AjaxResult.error("当前登录用户非经销商，不予该操作");
        }
        pOrder.setStatus("5");
        pOrder.setUpdateTime(new Date());
        pOrder.setUpdateBy(info.getLoginUser().getNickName());
        int result = pOrderMapper.updatePOrder(pOrder);
        if (result > 0){
            PWxLoginUser pWxLoginUser = pWxLoginUserMapper.selectPWxLoginUserById(preOrder.getUserId());
            if(pWxLoginUser != null && !"0".equals(pWxLoginUser.getSubscribeStatus())) {
                OrderWXMessage orderWXMessage = new OrderWXMessage();
                orderWXMessage.setCharacterString1(preOrder.getOrderNo());
                orderWXMessage.setThing2(preOrder.getRepairedPrice());
                orderWXMessage.setPhrase3("处理完成");
                orderWXMessage.setTime4(pOrder.getUpdateTime());
                orderWXMessage.setThing5("您好，供销商维修完成，请检查验收。");
                orderWXMessage.setToUser(pWxLoginUser.getOpenId());
                this.sendMessage(wxMessageProperties.getSchoolPage(),orderWXMessage);
            }

        }
        return AjaxResult.success("订单已完成，请等待学校验收");
    }
//    @Transactional
    @Override
    public AjaxResult checkOrder(LoginUserAndTokenVo info, UpdateOrderDto pOrder) {
        //（0 初始化 1 预约待报价状态 2 已接单,提醒到供销商 3 已报价待处理状态
        // 4 同意报价待处理状态 5 供销商处理完成，待学校验收
        // 6 学校验收通过 7后台完成了结算，已完成状态
        // -1 已关闭状态（后台手工））-2 不同意报价 -3 学校验收不通过
        POrder preOrder = pOrderMapper.selectPOrderById(pOrder.getId());
        if(!preOrder.getStatus().equals("5")){
            return AjaxResult.error("订单未处于完成状态，请等待经销商完成订单");
        }
        if(!"2".equals(info.getLoginType())){
            return AjaxResult.error("当前登录用户非学校，不予该操作");
        }
        pOrder.setUpdateTime(new Date());
        pOrder.setUpdateBy(info.getLoginUser().getNickName());
        int result = pOrderMapper.updatePOrder(pOrder);
        if (result > 0){
            PWxLoginUser pWxLoginUser = pWxLoginUserMapper.selectPWxLoginUserByContactId(preOrder.getDealerId());
            if(pWxLoginUser != null && !"0".equals(pWxLoginUser.getSubscribeStatus())) {
                OrderWXMessage orderWXMessage = new OrderWXMessage();
                orderWXMessage.setCharacterString1(preOrder.getOrderNo());
                orderWXMessage.setThing2(preOrder.getRepairedPrice());
                if (pOrder.getStatus().equals("6")) {
                    orderWXMessage.setPhrase3("验收通过");
                    orderWXMessage.setThing5("您好，学校验收通过，请前往结算。");
                } else {
                    orderWXMessage.setPhrase3("验收不通过");
                    orderWXMessage.setThing5("您好，学校没有通过验收，请前往处理。");
                }
                orderWXMessage.setTime4(pOrder.getUpdateTime());
                orderWXMessage.setToUser(pWxLoginUser.getOpenId());
                this.sendMessage(wxMessageProperties.getPage(),orderWXMessage);
            }
        }
        return AjaxResult.success("操作成功");
    }

    @Override
    public OrderVo getOrderInfo(Long id) {
        POrder preOrder =pOrderMapper.selectPOrderById(id);
        OrderVo vo = new OrderVo();
        BeanUtils.copyProperties(preOrder, vo);
        PFileInfo fileInfo = new PFileInfo();
        fileInfo.setContactId(id);
        List<PFileInfo> pFileInfos = fileInfoMapper.selectPFileInfoList(fileInfo);
        vo.setFileInfos(pFileInfos);
        return vo;
    }
    /**
     * 查询订单列表
     *
     * @param pOrder 订单
     * @return 订单
     */
    @Override
    public  List<POrder> selectPOrderList(LoginUserAndTokenVo info, FindOrderDto pOrder)
    {
        List<POrder> pOrders = pOrderMapper.selectPOrderList2(pOrder);
        if(!pOrders.isEmpty()) {
            //把地址的后面的详细地址删掉
            for (POrder order : pOrders) {
                order.setAddress(order.getAddress().split(" ")[0]);
            }
        }
        return pOrders;
    }
    /**
     * 查询订单列表
     *
     * @param pOrder 订单
     * @return 订单
     */
    @Override
    public String selectPOrderListSum(LoginUserAndTokenVo info, FindOrderDto pOrder,Integer count)
    {
        try {
            pOrder.setCount(count);
            return pOrderMapper.selectPOrderListSum(pOrder);
        }catch (Exception e){
            e.printStackTrace();
            return "0.00";
        }
    }
    @Override
    public List<DealerOrderVo> dealerOrders(LoginUserAndTokenVo info)
    {
        //获取登录用户
        PWxLoginUser pWxLoginUser = pWxLoginUserMapper.selectPWxLoginUserById(info.getLoginUser().getLoginUserId());
//        List<String> pDealers = dealerMapper.selectPDealers(pWxLoginUser.getContactId().toString());
        List<DealerOrderVo> result = new ArrayList<>();
        result.add(new DealerOrderVo("0",0,"初始化"));
        result.add(new DealerOrderVo("1",0,"预约待报价"));
        result.add(new DealerOrderVo("2",0,"已接单"));
        result.add(new DealerOrderVo("3",0,"待确认报价"));
        result.add(new DealerOrderVo("4",0,"同意报价"));
        result.add(new DealerOrderVo("5",0,"处理完成"));
        result.add(new DealerOrderVo("6",0,"验收通过"));
        result.add(new DealerOrderVo("7",0,"结算已完成"));
        result.add(new DealerOrderVo("-1",0,"已关闭"));
        result.add(new DealerOrderVo("-2",0,"不同意报价"));
        result.add(new DealerOrderVo("-3",0,"验收不通过"));
        List<DealerOrderVo> dealerOrderVos = pOrderMapper.dealerOrders(pWxLoginUser.getContactId());
        if(!dealerOrderVos.isEmpty()){
            //（0 初始化 1 预约待报价状态 2 已接单,提醒到供销商 3 已报价待处理状态
            // 4 同意报价待处理状态 5 供销商处理完成，待学校验收
            // 6 学校验收通过 7后台完成了结算，已完成状态
            // -1 已关闭状态（后台手工））-2 不同意报价 -3 学校验收不通过
            for( DealerOrderVo dealerOrderVo : dealerOrderVos){
                result.stream().forEach(bean ->{
                    if(bean.getStatus().equals(dealerOrderVo.getStatus())){
                        bean.setNum(dealerOrderVo.getNum());
                    }
                });
//                if(dealerOrderVo.getStatus())
//                switch (dealerOrderVo.getStatus()){
//                    case "0":
//                        dealerOrderVo.setStatusName("初始化");
//                        break;
//                    case "1":
//                        dealerOrderVo.setStatusName("预约待报价");
//                        break;
//                    case "2":
//                        dealerOrderVo.setStatusName("已接单");
//                        break;
//                    case "3":
//                        dealerOrderVo.setStatusName("已报价待处理");
//                        break;
//                    case "4":
//                        dealerOrderVo.setStatusName("同意报价待处理");
//                        break;
//                    case "5":
//                        dealerOrderVo.setStatusName("处理完成");
//                        break;
//                    case "6":
//                        dealerOrderVo.setStatusName("验收通过");
//                        break;
//                    case "7":
//                        dealerOrderVo.setStatusName("完成结算");
//                        break;
//                    case "-1":
//                        dealerOrderVo.setStatusName("已关闭状态");
//                        break;
//                    case "-2":
//                        dealerOrderVo.setStatusName("不同意报价");
//                        break;
//                    case "-3":
//                        dealerOrderVo.setStatusName("学校验收不通过");
//                        break;
//                }
            }
        }
        return result;
    }

    /**
     * 微信推送消息
     * @param orderWXMessage
     */
    private boolean sendMessage(String page,OrderWXMessage orderWXMessage){
        try {
            List<WxMaSubscribeMessage.MsgData> data = new ArrayList<>();
            WxMaSubscribeMessage.MsgData character_string1 = new WxMaSubscribeMessage.MsgData();
            character_string1.setName("character_string1");
            character_string1.setValue(orderWXMessage.getCharacterString1());
            WxMaSubscribeMessage.MsgData thing2 = new WxMaSubscribeMessage.MsgData();
            thing2.setName("thing2");
            if(StringUtils.isNotEmpty(orderWXMessage.getThing2())) {
                thing2.setValue(orderWXMessage.getThing2());
            }else{
                thing2.setValue("还未上报价格");
            }
            WxMaSubscribeMessage.MsgData phrase3 = new WxMaSubscribeMessage.MsgData();
            phrase3.setName("phrase3");
            phrase3.setValue(orderWXMessage.getPhrase3());
            WxMaSubscribeMessage.MsgData time4 = new WxMaSubscribeMessage.MsgData();
            time4.setName("time4");
            SimpleDateFormat format = new SimpleDateFormat("yyyy-MM-dd HH:mm:dd");
            time4.setValue(format.format(orderWXMessage.getTime4()));
            WxMaSubscribeMessage.MsgData thing5 = new WxMaSubscribeMessage.MsgData();
            thing5.setName("thing5");
            thing5.setValue(orderWXMessage.getThing5());
            data.add(character_string1);
            data.add(thing2);
            data.add(phrase3);
            data.add(time4);
            data.add(thing5);
            WxMaSubscribeMessage wxMaSubscribeMessage = new WxMaSubscribeMessage();
            wxMaSubscribeMessage.setTemplateId(wxMessageProperties.getTemplateId());
            wxMaSubscribeMessage.setMiniprogramState(wxMessageProperties.getMiniprogramState());
            wxMaSubscribeMessage.setPage(page);
//            wxMaSubscribeMessage.setPage(wxMessageProperties.getPage());
            wxMaSubscribeMessage.setData(data);
            wxMaSubscribeMessage.setToUser(orderWXMessage.getToUser());
            wxMaService.getMsgService().sendSubscribeMsg(wxMaSubscribeMessage);
            return true;
        }catch (WxErrorException we){
            if("43101".equals(we.getError().getErrorCode()+"")){
                //拒绝接受短信
                PWxLoginUser pWxLoginUser = new PWxLoginUser();
                pWxLoginUser.setOpenId(orderWXMessage.getToUser());
                List<PWxLoginUser> pWxLoginUsers = pWxLoginUserMapper.selectPWxLoginUserList(pWxLoginUser);
                pWxLoginUsers.stream().forEach(bean ->{
                    bean.setSubscribeStatus("0");
                    bean.setUpdateTime(new Date());
                    pWxLoginUserMapper.updatePWxLoginUser(bean);
                });
            }
            logger.debug("微信消息发送失败：",we.getMessage());
            return false;
        }
    }

    private static final ExecutorService executor = Executors.newCachedThreadPool() ;

    public void runSync(String orderNo,String price,Date time,String content,String openid) throws Exception {
        executor.submit(toRun(orderNo,price,time,content,openid));
    }
    public Runnable toRun(String orderNo,String price,Date time,String content,String openid){
        return new Runnable(){

            @Override
            public void run() {
                OrderWXMessage orderWXMessage = new OrderWXMessage();
                orderWXMessage.setCharacterString1(orderNo);
                orderWXMessage.setThing2(price);
                orderWXMessage.setPhrase3("验收通过");
                orderWXMessage.setTime4(time);
                orderWXMessage.setThing5(content);
                orderWXMessage.setToUser(openid);
                sendMessage(null,orderWXMessage);
            }
        };
    }
}
